package com.m2team.xomnhiepanh;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.etsy.android.grid.StaggeredGridView;
import java.util.ArrayList;
import java.util.Iterator;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class StaffChoiceFragment
  extends Fragment
  implements AbsListView.OnScrollListener, AdapterView.OnItemClickListener
{
  private static final String ARG_PARAM1 = "url";
  private static final String ARG_PARAM2 = "position";
  public static final String CSS_CLASS_IMAGE_HTML = ".padcol-left a";
  public static final String CSS_PROPERTY_HREF_IMAGE_HTML = "href";
  public static final String CSS_PROPERTY_LINK_IMAGE_HTML = "rel";
  public static final String CSS_PROPERTY_TITLE_IMAGE_HTML = "title";
  private static final String TAG = "StaffChoiceFragment";
  CustomAdapter adapter;
  StaggeredGridView gridView;
  private boolean mHasRequestedMore;
  private OnFragmentInteractionListener mListener;
  private String mParam1;
  int page = 1;
  ArrayList<Photo> photoList = new ArrayList();
  private int position = 0;
  ProgressBar progressBar;
  StringBuilder sb = new StringBuilder();
  TextView titleView;
  ArrayList<String> urlList = new ArrayList();
  
  public static StaffChoiceFragment newInstance(String paramString, int paramInt)
  {
    StaffChoiceFragment localStaffChoiceFragment = new StaffChoiceFragment();
    Bundle localBundle = new Bundle();
    localBundle.putString("url", paramString);
    localBundle.putInt("position", paramInt);
    localStaffChoiceFragment.setArguments(localBundle);
    return localStaffChoiceFragment;
  }
  
  public void onAttach(Activity paramActivity)
  {
    super.onAttach(paramActivity);
    try
    {
      this.mListener = ((OnFragmentInteractionListener)paramActivity);
      return;
    }
    catch (ClassCastException localClassCastException)
    {
      throw new ClassCastException(paramActivity.toString() + " must implement OnFragmentInteractionListener");
    }
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    if (getArguments() != null)
    {
      this.mParam1 = getArguments().getString("url");
      this.position = getArguments().getInt("position");
    }
  }
  
  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView1 = paramLayoutInflater.inflate(2130903072, paramViewGroup, false);
    this.gridView = ((StaggeredGridView)localView1.findViewById(2131099733));
    View localView2 = paramLayoutInflater.inflate(2130903079, null);
    this.progressBar = ((ProgressBar)localView2.findViewById(2131099750));
    this.gridView.addFooterView(localView2);
    this.adapter = new CustomAdapter(getActivity(), this.photoList);
    this.gridView.setAdapter(this.adapter);
    ParseURL localParseURL = new ParseURL();
    String[] arrayOfString = new String[1];
    arrayOfString[0] = this.mParam1;
    localParseURL.execute(arrayOfString);
    this.gridView.setOnScrollListener(this);
    this.gridView.setOnItemClickListener(this);
    return localView1;
  }
  
  public void onDetach()
  {
    super.onDetach();
    this.mListener = null;
  }
  
  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    if (paramInt < 0) {
      paramInt = 0;
    }
    for (;;)
    {
      Photo localPhoto = (Photo)this.photoList.get(paramInt);
      String str = localPhoto.getUrl().replace("thumb_", "");
      this.mListener.onFragmentInteraction(str);
      Intent localIntent = new Intent(getActivity(), ImageActivity.class);
      localIntent.putExtra("url", str);
      localIntent.putExtra("title", localPhoto.getTitle());
      localIntent.putExtra("author", localPhoto.getAuthor());
      localIntent.putExtra("href", localPhoto.getHref());
      startActivity(localIntent);
      return;
      if (paramInt > -1 + this.photoList.size()) {
        paramInt = -1 + this.photoList.size();
      }
    }
  }
  
  public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3)
  {
    if ((!this.mHasRequestedMore) && (paramInt1 + paramInt2 >= paramInt3))
    {
      if (this.photoList.size() > 0)
      {
        if (this.photoList.size() > 35) {
          break label165;
        }
        this.page = 2;
      }
      switch (this.position)
      {
      default: 
        this.sb = new StringBuilder("http://xomnhiepanh.com/?mod=gallery&act=staffchoice").append("&sort=&dir=&page=").append(this.page);
      }
    }
    for (;;)
    {
      Log.d("StaffChoiceFragment", "onScroll lastInScreen - so load more url: " + this.sb.toString());
      this.mHasRequestedMore = true;
      ParseURL localParseURL = new ParseURL();
      String[] arrayOfString = new String[1];
      arrayOfString[0] = this.sb.toString();
      localParseURL.execute(arrayOfString);
      return;
      label165:
      this.page = (1 + paramInt3 / 35);
      break;
      this.sb = new StringBuilder("http://xomnhiepanh.com/?mod=gallery&act=staffchoice").append("&sort=&dir=&page=").append(this.page);
      continue;
      this.sb = new StringBuilder("http://xomnhiepanh.com/?mod=gallery&act=categories&catid=6&t=phong-canh-landscape").append("&page=").append(this.page);
    }
  }
  
  public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt) {}
  
  public static abstract interface OnFragmentInteractionListener
  {
    public abstract void onFragmentInteraction(String paramString);
  }
  
  class ParseURL
    extends AsyncTask<String, Void, ArrayList<Photo>>
  {
    StringBuilder linkBuilder = new StringBuilder();
    
    ParseURL() {}
    
    protected ArrayList<Photo> doInBackground(String... paramVarArgs)
    {
      for (;;)
      {
        try
        {
          localIterator = Jsoup.connect(paramVarArgs[0]).get().select(".padcol-left a").iterator();
          boolean bool = localIterator.hasNext();
          if (bool) {
            continue;
          }
        }
        catch (Throwable localThrowable)
        {
          Iterator localIterator;
          Element localElement;
          String str1;
          String str2;
          String str3;
          String str4;
          String[] arrayOfString;
          Photo localPhoto;
          localThrowable.printStackTrace();
          continue;
          String str5 = "";
          continue;
          String str6 = "";
          continue;
        }
        return StaffChoiceFragment.this.photoList;
        localElement = (Element)localIterator.next();
        str1 = localElement.attr("rel");
        str2 = str1.substring(0, str1.indexOf("@"));
        str3 = localElement.attr("title");
        str4 = localElement.attr("href");
        arrayOfString = str3.split("-");
        if (arrayOfString[0] == null) {
          continue;
        }
        str5 = arrayOfString[0].trim();
        if (arrayOfString[1] == null) {
          continue;
        }
        str6 = arrayOfString[1].trim();
        if (!StaffChoiceFragment.this.urlList.contains(str2))
        {
          localPhoto = new Photo(str5, str2, str6, str4);
          StaffChoiceFragment.this.photoList.add(localPhoto);
          StaffChoiceFragment.this.urlList.add(str2);
        }
      }
    }
    
    protected void onPostExecute(ArrayList<Photo> paramArrayList)
    {
      super.onPostExecute(paramArrayList);
      if (paramArrayList.size() == 0) {
        Toast.makeText(StaffChoiceFragment.this.getActivity(), StaffChoiceFragment.this.getString(2131034160), 0).show();
      }
      StaffChoiceFragment.this.adapter.notifyDataSetChanged();
      StaffChoiceFragment.this.mHasRequestedMore = false;
      StaffChoiceFragment.this.progressBar.setVisibility(4);
    }
    
    protected void onPreExecute()
    {
      super.onPreExecute();
    }
  }
}



/* Location:           C:\Users\Administrator\Downloads\Convert APK to Code\dex2jar-0.0.9.15\dex2jar-0.0.9.15\classes-dex2jar.jar

 * Qualified Name:     com.m2team.xomnhiepanh.StaffChoiceFragment

 * JD-Core Version:    0.7.0.1

 */